package com.yanqu.road.server.cmd.orewar;

import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.OreWarModule;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code= Protocol.S_ORE_WAR_REFUGE_RECALL, desc = "矿场避难所召回")
public class OreRefugeRecallCmd extends AbstractCommand {

    int activityId;

    int pitId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OreWarProto.OreRefugeRecallReqMsg reqMsg = OreWarProto.OreRefugeRecallReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        pitId = reqMsg.getPitId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!OreWarMgr.isActivityActive(activityId)){
            ret = GameErrorCode.E_ORE_ACTIVITY_NO_IN_DAY_TIME;
            return;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        OreWarProto.OreRefugeRecallRespMsg.Builder resMsg = OreWarProto.OreRefugeRecallRespMsg.newBuilder();
        if(ret == 0){
            resMsg = player.getModule(OreWarModule.class).refugeRecall(activityId, pitId);
        }
        resMsg.setRet(ret);
        player.sendPacket(Protocol.U_ORE_WAR_REFUGE_RECALL, resMsg);
    }
}
